package com.iooiee.example_helloworld;

import org.apache.mina.core.service.IoHandlerAdapter;
import org.apache.mina.core.session.IdleStatus;
import org.apache.mina.core.session.IoSession;

/**
 * 业务实现对象
 */
public class MyServerHandler extends IoHandlerAdapter {
    public MyServerHandler() {
        super();
    }

    @Override
    public void sessionCreated(IoSession session) throws Exception {
        System.out.println("sessionCreated");
        super.sessionCreated(session);
    }

    @Override
    public void sessionOpened(IoSession session) throws Exception {
        System.out.println("sessionOpened");
        super.sessionOpened(session);
    }

    @Override
    public void sessionClosed(IoSession session) throws Exception {
        System.out.println("sessionClosed");
        super.sessionClosed(session);
    }
    //空闲状态
    @Override
    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
        System.out.println("sessionIdle");
        super.sessionIdle(session, status);
    }

    // 连接出现异常
    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        System.out.println("exceptionCaught");
        super.exceptionCaught(session, cause);
    }
    //接收到数据后要处理的事情
    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {
        System.out.println("服务端接收到数据"+message.toString());
        super.messageReceived(session, message);
    }

    @Override
    public void messageSent(IoSession session, Object message) throws Exception {
        System.out.println("messageSent");
        super.messageSent(session, message);
    }
}
